#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/6/10 0010 21:35
# @Author  : wzy
# @Site    : 
# @File    : test01case.py
# @Software: PyCharm

import json
import unittest

import paramunittest as paramunittest

from testFile.getpathInfo import get_path
from common.configHttp import runmain
from testFile.geturlParams import getUrlParams
import urllib.parse
from testFile.readExcel import readExcel
from common.log import logger
log = logger
url = getUrlParams.get_url()
login_xls = readExcel.get_xls('userCase.xlsx','login')
# 加载userCase.xlsx，设置参数（与excel列名一致）
@paramunittest.parametrized(*login_xls)
class testUserlogin(unittest.TestCase):
    def setParameters(self, case_name, path, query, method):
        '''
        :param case_name:
        :param path:
        :param query:
        :param method:
        :return:
        '''
        self.casename = str(case_name)
        self.path = str(path)
        self.query = str(query)
        self.method = str(method)
        print("case name-----" + self.casename)

    def description(self):
        self.casename
        print(self.casename)

    def setUp(self) -> None:
        print("----用例开始------")

    def test01case(self):
        self.checkResult()

    def tearDown(self) -> None:
        print("----用例结束------")

    def checkResult(self):
        '''
        :return:检查返回结果
        '''
        new_url1 = url +self.query
        #  data1 字典
        data1 = dict(urllib.parse.parse_qsl(urllib.parse.urlsplit(new_url1).query))
        # 传入 method url  data
        info = runmain.run_main(self.method,url,data1)
        inParamas = json.loads(info)
        if self.casename == 'login':  # 如果case_name是login，说明合法，返回的code应该为200
            self.assertEqual(inParamas['code'], 200)
        if self.casename == 'login_error':  # 同上
            self.assertEqual(inParamas['code'], -1)
        if self.casename == 'login_null':  # 同上
            self.assertEqual(inParamas['code'], 10001)
if __name__ == '__main__':

    pass